﻿using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1.function
{
    public class json
    {
        public static void createVmFromJsonFile(string strjsonfile)
        {
            try
            {
                string strJson = File.ReadAllText(strjsonfile);

                if (IsJOjbect(strJson))
                {
                    JObject jo = (JObject)JsonConvert.DeserializeObject(strJson);

                    foreach (var item in jo)
                    {
                        
                        if (item.Value.GetType() == typeof(JObject))
                        {
                            //Console.WriteLine(item.Value);
                        }
                        else if (item.Value.GetType() == typeof(JArray))
                        {
                          
                        }
                        else
                        {
                            string s = " public string " + item.Key + " { get; set; }";
                            Console.WriteLine(s);
                            //Console.WriteLine(item.Key);
                        }
                    }
                }
            }
            catch (Exception)
            {
                Console.WriteLine("json convert failed");
            }
        }

        public static bool IsJOjbect(string value)
        {
            try
            {
                JObject ja = JObject.Parse(value);
                return true;
            }
            catch (Exception ex)
            {
                return false;
            }
        }
    }
}
